<template>
  <div>
    <el-table :data="purchases">
      <el-table-column prop="buyNumber" label="采购编号"></el-table-column>
      <el-table-column prop="totalMoney" label="采购总金额(元)"></el-table-column>
      <el-table-column prop="totalNum" label="采购总数量"></el-table-column>
      <el-table-column prop="ptime" label="采购时间"></el-table-column>
      <el-table-column prop="user.uname" label="供应商"></el-table-column>
      <el-table-column label="采购单状态">
        <el-tag type="warning">总店发起采购，等待发货</el-tag>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-dropdown split-button type="primary" @click="showDetail(scope.row.id)">
            查看详情
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <el-button size="medium" type="danger" @click="deliverGoods(scope.row.id)">确认发货</el-button>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageno"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
    <div>
      <ShowDetails ref="showDetails"></ShowDetails>
    </div>
  </div>
</template>

<script>
    import ShowDetails from "../../../liwentao/purchase/ShowDetails";
    export default {
        name: "supplier_delivery",
        data() {
          return {
            purchases: [],
            purchase: {
              buyNumber: "",
              supplyId:sessionStorage.getItem("id"),//供应商id
              isShipments:0,//未发货
              isAudit:1//审核通过
            },
            pageno: 1,
            pagesize: 5,
            total: 1
          }
        },
        methods: {
          getPurchases() {
            var params = new URLSearchParams();
            params.append("pageno", this.pageno);
            params.append("pagesize", this.pagesize);
            Object.keys(this.purchase).forEach(item => {
              params.append(item, this.purchase[item]);
            })
            this.$axios.get("purchase/purchase.action", {params: params})
              .then(res => {
                this.purchases = res.data.records;
                this.total = res.data.total;
              })
              .catch(err => {
                this.$message.error(err)
              })
          },
          showDetail(pid) {
            this.$refs.showDetails.dialogVisible = true;
            this.$refs.showDetails.purchaseDetail.pid = pid;
            this.$refs.showDetails.getData();
          },
          deliverGoods(id){
            let purchaseInfo={
              id:id,
              isShipments:1//设置为发货
            };
            //调用异步，进行发货
            this.$axios.post("supplierSupplyOfGoods/supplierDelivery.action",purchaseInfo)
              .then(res=>{
                if(res.data.x){
                  this.$message.success(res.data.msg);
                }else {
                  this.$message.error(res.data.msg);
                }
                //重新查询一次数据
                this.getPurchases();
              })
              .catch(err=>{
                this.$message.warning(err);
                alert(err);
              })
          },
          handleSizeChange(val) {
            //每页范围
            this.pagesize = val;
            this.getPurchases();
          },
          handleCurrentChange(val) {
            //当前页
            this.pageno = val;
            this.getPurchases();
          },
        },
        components: {
          ShowDetails
        },
        created() {
          this.getPurchases();
        }
    }
</script>

<style scoped>

</style>
